﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CreateRiskDB.aspx.cs" Inherits="SkWeb.RiskDB.CreateRiskDB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	
	<%--<link rel="stylesheet" type="text/css" href="../themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="../themes/icon.css">
	<link rel="stylesheet" type="text/css" href="demo.css">--%>
    <link href="../easyui/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../easyui/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../easyui/jquery-1.8.0.min.js" type="text/javascript"></script>
    <script src="../easyui/jquery.easyui.min.js" type="text/javascript"></script>
	<script type="text/javascript">
	    var s = 2000;
	    $(function () {
	        $('#test').treegrid({
	            title: '构建风险数据库',
	            iconCls: 'icon-ok',
	            rownumbers: true,
	            animate: true,
	            collapsible: true,
	            fitColumns: true,
	            rownumbers: true,
	            pagination: true,
	            url: 'Handler.ashx?name=EMP',
	            idField: 'id',
	            treeField: 'Name',
	            showFooter: true,
	            rowStyler: function (row) {
	                if (row.persons > 1) {
	                    return 'background:#AAD684;color:#fff';
	                }
	            },
	            columns: [[
	                { title: 'Task Name', field: 'Name', editor: 'text', width: 180 },
					{ field: 'Type', title: 'Type', width: 60, align: 'right' },
					{ field: 'Precision', title: 'Precision', width: 80 },
					{ field: 'Start', title: 'Start', editor: 'text', width: 80, rowspan: 2 },
                    { field: 'End', title: 'End', width: 80, editor: 'text', rowspan: 2 },
                    { field: 'Level', title: 'Level', editor: 'text', width: 80 },
                    { field: 'Describe', title: 'Describe', width: 80, editor: 'text', rowspan: 2 },
	            //					{ field: 'End', title: 'End', width: 120, rowspan: 2,
	            //					    formatter: function (value) {
	            //					        if (value) {
	            //					            var s = '<div style="width:100%;background:#fff;border:1px solid #ccc">' +
	            //						    			'<div style="width:' + value + '%;background:red">' + value + '%' + '</div>'
	            //					            '</div>';
	            //					            return s;
	            //					        } else {
	            //					            return '';
	            //					        }
	            //					    }
	            //					}
				]],

	            toolbar: [{
	                text: 'edit',
	                iconCls: 'icon-edit',
	                handler: function () {
	                    editNode();
	                }
	            }, '-', {
	                text: 'add',
	                iconCls: 'icon-add',
	                handler: function () {
	                    addNode();
	                }
	            }, '-', {
	                text: 'delete',
	                iconCls: 'icon-remove',
	                handler: function () {
	                    cancelNode();
	                }
	            }, '-', {
	                text: 'accept',
	                iconCls: 'icon-save',
	                handler: function () {
	                    saveNode();
	                }
	            }, '-', {
	                text: 'reject',
	                iconCls: 'icon-undo',
	                handler: function () {
	                    // $('#test').treegrid('rejectChanges');
	                    $('#test').treegrid('reload'); // reload the all rows
	                }
	            }, '-', {
	                text: 'GetChanges',
	                iconCls: 'icon-search',
	                handler: function () {
	                    var rows = $('#test').treegrid('getChanges');
	                    alert('changed rows: ' + rows.length + ' lines');
	                }
	            }]


	        });
	    });
	</script>


</head>
<body>
<form runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
    </asp:ScriptManager>
    <script type="text/javascript">
        function addNode() {
            // call the server side method here
            PageMethods.genId(OnSuccess);
        }
        function OnSuccess(result) {
            var node = $('#test').treegrid('getSelected');
            var childnode = $('#test').treegrid("getChildren", node.id);
            var parentnode = $('#test').treegrid("getParent", node.id);
            if (childnode.length < 1&&parentnode!=null) {
                $('#test').treegrid('insert', {
                    after: node.id,
                    data: {
                        id: result,
                        Name: "修改默认值",
                        Type: " ",
                        Precision: " ",
                        Start: 0,
                        END: 0,
                        Level: 0,
                        Describe: " ",
                        _parentId: ($('#test').treegrid("getParent", node.id)).id
                    }
                });
            }
            else {
                $('#test').treegrid('append', {
                    parent: node.id,
                    data: [{
                        id: result,
                        Name: "修改默认值",
                        Type: " ",
                        Precision: " ",
                        Start: 0,
                        END: 0,
                        Level: 0,
                        Describe: " ",
                        _parentId: node.id
                    }]
                });

            }
        }


        function saveNode() {
            var node = $('#test').treegrid('getSelected');
            if (node) {
                $('#test').treegrid('endEdit', node.id);
                var Tname = "EMP"; //$('#text').val;
                var pCname = $('#test').treegrid('getParent', node.id).Name;
                var node = $('#test').treegrid('getSelected');
               // alert(JSON.stringify(node));
                PageMethods.updateNode(JSON.stringify(node),pCname,Tname, OnResult, OnError);

            }

        }
        function OnResult(result, userContext, method) {//
            alert(result);
        }
        function OnError(error, userContext, method) {
            alert(error);
        }

</script>
</form>
   <%-- <form id="form1" runat="server">--%>
    <div>
    <div class="demo-info" style="margin-bottom:10px">
		<div class="demo-tip icon-tip"></div>
		
	</div>
	
	<table id="test"   title="TreeGrid" class="easyui-treegrid" style="width:800px;height:300px"></table>
    </div>
    <%--</form>--%>
    <script type="text/javascript">
         function formatProgress(value) {
             if (value) {
                 var s = '<div style="width:100%;border:1px solid #ccc">' +
                        '<div style="width:' + value + '%;background:#cc0000;color:#fff">' + value + '%' + '</div>'
                 '</div>';
                 return s;
             } else {
                 return '';
             }
         }
        
     
		function editNode(){
			var node = $('#test').treegrid('getSelected');
			if (node){
				$('#test').treegrid('beginEdit',node.id);
			}
		}
		
		function cancelNode(){
			var node = $('#test').treegrid('getSelected');
			if (node){
			    $('#test').treegrid('remove', node.id);
			}
		}
	


    </script>


</body>
</html>
